package com.metaverse.backend.repo;

import com.alibaba.fastjson.JSONObject;
import com.metaverse.backend.domain.User;
import com.metaverse.backend.security.Authority;
import org.springframework.cache.annotation.CacheEvict;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.lang.NonNull;

import javax.transaction.Transactional;
import java.time.LocalDateTime;
import java.util.List;
import java.util.Map;
import java.util.Optional;

public interface UserRepo extends JpaRepository<User, Long>, JpaSpecificationExecutor<User> {
    @Transactional
    @Modifying
    @Query("update User u set u.del = true where u.id = ?1")
    void softDelete(Long id);

    @Query(value = "select * " +
            "from user " +
            "where openid = ?1", nativeQuery = true)
    User findByOpenid(String openid);



    @Query(value = "select * " +
            "from user " +
            "where username = ?1", nativeQuery = true)
    User findByUsername(String username);


    @Query(value = "select id " +
            "from user ", nativeQuery = true)
    List<Long> findUserIds();
}
